﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Home.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" 
Inherits="LizzabethBrownRealEstate.Views.Home.Index" %>
<%@ Import Namespace="LizzabethBrownRealEstate.Models" %>
<%@ Import Namespace="LizzabethBrownRealEstate.Controllers" %>


<asp:Content ID="Content1" ContentPlaceHolderID="ScriptPlaceHolder" runat="server">
    <script type="text/javascript">
       
        $(document).ready(function(){
        
            $('#UserName').focus();
            $('#fldLogin').dropShadow({left: 4, top: 15, blur: 8});
            $('#fldTips').dropShadow({left: 4, top: 15, blur: 8});
            $('#fldResources').dropShadow({left: 4, top: 15, blur: 8});
            $('#fldFeatures').dropShadow({left: 4, top: 15, blur: 8});
            $('#fldEvents').dropShadow({left: 4, top: 15, blur: 8});
            $(".SiteMap").hide();
            });
    </script>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="StylePlaceHolder" runat="server">
    <style type="text/css">
        .NewsTitle a { font-size: 1.2em; font-weight: bold; color: Maroon; text-decoration: none; }
        .NewsTitle a:hover { font-size: 1.2em; font-weight: bold; color:#663300; text-decoration: none; }
        .NewsBody { font-size: .8em; }
        .more a { font-size: .8em; color:Olive; }
    </style>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
  <% LBRDataContext c = new LBRDataContext(); %>
  <div class="contentDiv">
        <table style="width:100%; margin-left:25px; margin-right:25px; border-collapse:collapse;">
        <tr>
            <td style="width:50%; vertical-align: top;">
                <% if (Membership.GetUser() == null)
                   { %>
                <form id="frmLogin" method="post" action="<%= Url.Action("Authenticate", "Users") %>" >
                    
                    <fieldset id="fldLogin">
                        <legend>Log In</legend>
                        <table>
                            <tr>
                                <td class="label" style="height: 25px; text-align:right; padding-right:5px;">User Name</td><td><%=Html.TextBox("UserName")%></td>
                            </tr>
                            <tr>
                                <td class="label" style="height: 25px; text-align:right; padding-right:5px;">Password</td><td><%=Html.Password("Password")%></td>
                            </tr>
                            <tr>
                                <td colspan="2" style="height: 25px;">
                                    <span class="linktableButton"><input type="submit" value="Log In" /></span>
                                    <span class="linktableButton"><%= Html.ActionLink("Register", "RegisterInfo", "Users")%></span>
                                    <span class="linktableButton"><input type="checkbox" checked="checked" name="RememberMe" /><label for="RememberMe">Remember Me</label></span>
                                </td>
                            </tr>
                        </table>
                        
                    </fieldset>
                </form>
                <% }
                   else
                   {  %>
                    <fieldset id="fldTips">
                    <legend style="font-weight:bold; font-style:italic">Did you know...</legend>
                    <% foreach (NewsItem n in c.NewsItems.Where<NewsItem>(n => n.Featured.Value == true && n.Deleted == false))
                       { %>
                        <div style="position:relative; margin-bottom:10px; ">
                            <span class="NewsTitle"><%= Html.ActionLink(n.Title, "ReadNewsItem", "Users", new { newsItemId = n.NewsItemId }, null)%></span><br />
                            <span class="NewsBody"><%= n.Body.Substring(0, (n.Body.Length>120 ? 120 : n.Body.Length)) + ((n.Body.Length) > 120 ? "..." : "") %> </span>
                            <span class="more"><%= Html.ActionLink("more", "ReadNewsItem", "Users", new { newsItemId = n.NewsItemId }, null)%></span>
                        </div>
                    <%} %>
                </fieldset>
                <% } %>
            </td>
            <td style="width:50%;">
                <fieldset id="fldResources">
                    <legend>Buyer/Seller Resources</legend>
                    <ul style="margin-top:-5px;">
                    <% foreach (Resource r in c.Resources.OrderBy(r=>r.DisplayOrder))
                       {
                           bool display = !r.Deleted;
                           if (Membership.GetUser() != null)
                           {
                               if (!Roles.IsUserInRole(Membership.GetUser().UserName, "Administrator") && r.Private)
                               {
                                   display = false;
                               }
                           }
                           else
                           {
                               display = display & !r.Private;
                           }
                           if (display)
                           { %>
                            <li><a href='<%= Html.Encode(r.Url) %>' class="linktableButton" target="_blank" ><%= Html.Encode(r.Caption)%></a></li>
                            <%}
                       }%>
                    </ul>
                </fieldset>
            </td>
        </tr>
        <tr><td colspan="2">&nbsp;</td></tr>
        <tr>
            <td style="width:50%;">
                <fieldset id="fldFeatures">
                <legend>Featured Properties</legend>
                <% HomeController hc = new HomeController(); %>
                    <% foreach (RealEstateProperty p in hc.GetFeaturedProperties()) %>
                    <%{ %>
                    <div>
                        <% if (p.Photos.Count > 0)
                           { object propId = new { propertyId = p.PropertyId }; %>
                            <table width="100%">
                                <tr>
                                    <td colspan="2" style="text-align:center;">
                                        <% object vals = new {_class="featuredProperty" }; %>
                                        <% Photo pfoto = p.Photos.Where<Photo>(foto => foto.Featured == true).SingleOrDefault<Photo>(); %>
                                        <% if (pfoto != null)
                                           { %>
                                        <a href="<%= Url.Action("ViewProperty", "Home", propId ) %>"><img src="<%= Url.Content("~/Repository/" + pfoto.FileName) %>"  alt="Featured Property" class="featuredProperty" /></a>
                                        <%} %>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="label">Location:</td><td><%=p.Location.Name %></td>
                                </tr>
                                <tr>
                                    <td class="label">Price:</td><td><%= String.Format("{0:C}", p.Price) %></td>
                                </tr>
                                <tr>
                                    <td style="border:dashed 1pt silver; padding:5px 5px 5px 5px; text-align:left" colspan="2"><%= p.Description %></td>
                                </tr>
                            </table>
                        <%} %>
                    </div>
                    <%} %>                    
                </fieldset>                    
            </td>
            <td style="width:50%;">
                <fieldset id="fldEvents">
                    <legend>Upcoming Events/Showings</legend>
                    <table width="100%">
                        <% foreach (Event e in c.Events.Where<Event>(e=>e.EventStart.Value > System.DateTime.Now && e.Deleted==false).OrderBy<Event, DateTime>(e=>e.EventStart.Value))
                           { %>
                        <tr>
                            <% object eventId = new { eventId = e.EventId }; %>
                            <td class="linktableButton"><%= Html.ActionLink(e.Title, "ViewEvent", eventId, null)%></td>
                            <td class="label"><%= e.EventStart.Value.ToShortDateString() %></td>
                        </tr>
                        <%} %>
                    </table>
                </fieldset>
            </td>
        </tr>
        </table>
  </div>
</asp:Content>

